//声明构造函数   测试 Git 拉取
function Promise(executor) {
  //状态属性
  this.PromiseState = "pending";
  //结果值属性
  this.PromiseResult = undefined;
  //resolve 函数
  //更改 promise 实例对象状态为成功, 设置成功的结果值
  let success = (value) => {
    //判断状态是否为 pending
    if(this.PromiseState !== 'pending') return;
    //更改 promise 实例对象状态为成功
    this.PromiseState = "fulfilled";
    //设置成功的结果值
    this.PromiseResult = value;
  };

  //reject 函数
  let fail = (reason) => {
    //判断状态是否为 pending
    if(this.PromiseState !== 'pending') return;
    //更改 promise 实例对象状态为失败
    this.PromiseState = "rejected";
    //设置成功的结果值
    this.PromiseResult = reason;
  };

  try {
    //执行器函数是一个同步回调
    executor(success, fail);
  } catch (e) {
    //更改 promise 实例对象状态为失败
    fail(e);
  }
}

//原型声明 then 方法
Promise.prototype.then = function (onFulfilled, onRejected) {
  //判断
  if (this.PromiseState === "fulfilled") {
    onFulfilled(this.PromiseResult);
  }

  if (this.PromiseState === "rejected") {
    onRejected(this.PromiseResult);
  }
};

//执行函数的方式
// fn     fn()   fn.call()   fn.apply()
//函数基础
// 函数声明, 函数调用, 函数传参, 函数返回值
/*
  函数声明:  function fn(a ,b){}   let fn = function(){}  let fn = () => {}
  函数调用:  fn()   fn.call()   fn.apply()  
  函数传参:  fn(1,2)   fn.call(obj, 3, 4)   fn.apply(obj, [5,6])
  函数返回值:  let fn = () => {}   fn 此时返回值为 undefined
              let fn =() => {     fn 此时返回值为 undefined
                console.log(123);
                return;
              }

 

*/
